define( [ "jquery", "jquery.artDialog" ], function($) {
	var article = {};
	//创建索引
	article.createIndexes = function() {
		$.dialog( {
			lock : true,
			background : '#000000',
			opacity : 0.5,
			fixed : true,
			drag : false,
			resize : false,
			title : '消息提示',
			content : '此操作会重置所有索引文件，确认继续吗？',
			button : [ {
				name : '确定',
				callback : function() {
					$.ajax( {
						type : "POST",
						url : "admin/generateIndexes",
						success : function(msg) {
							alert(msg);
						}
					});
				}
			}, {
				name : '取消'
			} ]
		});
	}
	//删除文章
	article.deleteArticle = function() {
		var href = $(this).attr("ref");
		$.dialog( {
			lock : true,
			background : '#000000',
			opacity : 0.5,
			fixed : true,
			drag : false,
			resize : false,
			title : '消息提示',
			content : '确定删除此文章吗？',
			button : [ {
				name : '确定',
				callback : function() {
					$.ajax( {
						type : "POST",
						url : href,
						success : function(msg) {
							alert(msg);
							window.location.href = window.location.href;
						}
					});
				}
			}, {
				name : '取消'
			} ]
		});
	}
	//发布文章
	article.initPublish = function(artid) {
		if (artid != '') {
			$("#leftfrm").attr("src", "admin/lefting/" + artid);
			$("#rightFrame").attr("src", "admin/centering/" + artid);
		}
	}
	//发布文章center
	article.artCenter = function(artpic, artpic2, isdraft, artid) {
		if (artpic == '') {
			$("#admin_img").attr("src", artpic2);
			$("#art_hidden").val(artpic2);
		} else {
			$("#admin_img").attr("src", artpic);
			$("#art_hidden").val(artpic);
		}
		if (isdraft == '1') {
			$("option[value='1']").attr("selected", "selected");
		}
		if (artid != '') {
			$("#admin_status").val(10010);
		}
	}
	//发布功能
	$("#admin_publish").click(function() {
		if ($("#bindid").val() == '') {
			alert("您必须选择一个分类");
			return;
		}
		if ($("#arttitle").val() == '') {
			alert("您必须设置一个标题");
			return;
		}
		if ($("#admin_status").val() == 10010) {
			$("#form1").attr("target", "_parent");
		}
		$("#form1").submit();
	});
	
	//选择历史
	$("#choose_history").click(function(){
		$.dialog( {
			lock : true,
			background : '#000000',
			opacity : 0.5,
			fixed : true,
			drag : false,
			resize : false,
			cancel : false,
			title : '选择历史',
			content : document.getElementById("history_dialog"),
			button : [ {
				name : '取消'
			} ]
		});
	});
	//图片点击
	$("img[id^='history_img']").click(function(){
		$("#art_hidden").val($(this).attr("src"));
		var list = $.dialog.list;
		for (var i in list) {
		    list[i].close();
		};
	});
	
	
	//发布文章left
	article.artLeft = function(artid) {
		if (artid != '') {
			$("#leftfrm").attr("src", "admin/lefting/" + artid);
			$("#rightFrame").attr("src", "admin/centering/" + artid);
		}
	}
	return article;
});